<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<link rel="stylesheet" href="${webcontext}/res/style/S.css" />
	<script type="text/javascript" src="${webcontext }/res/js/jquery.min.js"></script>
	<script type="text/javascript" src="${webcontext }/res/js/S.js"></script>
	<script type="text/javascript">
		$(function(){
			var select = new S.Select({
				el:'#projects_select',
				ds:'${webcontext}/${pathvar.admin}/br/project/projects',
				clear:false,
				render:function(p){
					return p.name;
				},
				change:function(p){
					var id = '';
					if(p){id = p.id;}
					$('#tg_projectId').val(p.id);
					tbl.load('${webcontext}/${pathvar.admin}/br/testing/group/list?projectId='+id);
				}
			});
			
			var tbl = new S.Table({
				el:'#tbl_001',
				pager:true,
				scroll:true,
				pageSize:30,
				multiselect:false,
				dbclick:function(data){
					editTGroup(data);
				},
				menus:{
					'打开':function(tr){
						var idx= $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						window.location.href='${webcontext }/${pathvar.admin}/br/testing/tp?tg='+data.id;
					},
					'编辑':function(tr){
						var idx= $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						editTGroup(data);
					},
					'复制组':function(tr){
						var idx= $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						copyTGroup(data);
					},
					'导出':function(tr){
						var idx= $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						exportTGroup(data);
					},
					'删除':function(tr){
						var idx= $(tr).index();
						var data = tbl.data[idx];
						if(data == null){return;}
						deleteTGroup([data]);
					}
				}
			});
			
			
			$('#btn_testgroup_add').click(function(){
				var dlg = new S.Dialog({
					title:'增加测试组',
					modal:true,
					width:500,
					height:350,
					url:'${webcontext}/${pathvar.admin}/br/testing/group/edit?projectId='+$('#tg_projectId').val(),
					buttons:{
						'保存':function(){
							
							if(!this.form.validate()){new S.Info({text:'表单填写不完整',type:'warn'}).show();return;}
							S.request({
								url:'${webcontext}/${pathvar.admin}/br/testing/group/save',
								data:this.form.param(),
								success:function(){
									new S.Info({text:'操作成功',type:'success'}).show();
									tbl.reload();
									dlg.remove();
								}
							});
						},
						'取消':function(){
							this.remove();
						}
					}
				});
				dlg.show();
			});
			
			
			function editTGroup(data){
				var dlg = new S.Dialog({
					title:'编辑测试组',
					modal:true,
					width:500,
					height:350,
					url:'${webcontext}/${pathvar.admin}/br/testing/group/edit?id='+data.id,
					buttons:{
						'保存':function(){
							if(!this.form.validate()){new S.Info({text:'表单填写不完整',type:'warn'}).show();return;}
							S.request({
								url:'${webcontext}/${pathvar.admin}/br/testing/group/update',
								data:this.form.param(),
								success:function(){
									new S.Info({text:'操作成功',type:'success'}).show();
									tbl.reload();
									dlg.remove();
								}
							});
						},
						'取消':function(){
							this.remove();
						}
					}
				});
				dlg.show();
			}
			
			$('#btn_testgroup_edit').click(function(){
				
				var items = tbl.getCheckedRow();
				if(items.length!=1){new S.Info({text:'请选择测试组',type:'warn'}).show();return;}
				editTGroup(items[0]);
				
			});
			
			
			function deleteTGroup(items){
				S.confirm('警告','确认要删除选中的测试组?',function(){
					var ids = [];
					S.each(items,function(i,item){
						ids.push(item.id);
					});
					S.request({
						url:'${webcontext}/${pathvar.admin}/br/testing/group/delete',
						data:{ids:ids.join(',')},
						success:function(){
							new S.Info({text:'操作成功',type:'success'}).show();
							tbl.reload();
						}
					});
				},'danger');
			}
			
			$('#btn_testgroup_delete').click(function(){
				
				var items = tbl.getCheckedRow();
				if(items.length==0){new S.Info({text:'请选择测试组',type:'warn'}).show();return;}
				deleteTGroup(items);
			});
			
			
			function exportTGroup(data){
				window.open('${webcontext}/${pathvar.admin}/br/testing/export?id='+data.id);
			}
			
			$('#btn_testgroup_export').click(function(){
				
				var items = tbl.getCheckedRow();
				if(items.length!=1){new S.Info({text:'请选择测试组',type:'warn'}).show();return;}
				
				exportTGroup(items[0]);
				
				
			});
			
			
			function copyTGroup(data){
				var dlg = new S.Dialog({
					title:'复制选项',
					width:500,
					height:250,
					modal:true,
					content:'<div class="content"><form><table width="100%"><tr><td width="80">新组名称</td><td><input type="text" name="name" class="long" check="required"/></td></tr><tr><td width="80">版本号</td><td><input type="text" name="version" /></td></tr><tr><td>测试时间</td><td><input type="text" name="startTime" datetype="yyyy-MM-dd HH:mm:ss"/> 至  <input type="text" name="endTime" datetype="yyyy-MM-dd HH:mm:ss"/></td></tr><tr><td>复制项</td><td><input type="checkbox" name="caseType" value="all" checked="checked"/>全部　<input type="checkbox" name="caseType" value="fail"/>仅失败</td></tr></table></form></div>',
					buttons:{
						'确认':function(){
							if(!this.form.validate()){new S.Info({text:'表单填写不完整',type:'warn'}).show();return;}
							S.request({
								url:'${webcontext}/${pathvar.admin}/br/testing/group/copy',
								data:S.fixConfig(this.form.param(),{from:data.id}),
								success:function(){
									new S.Info({text:'操作成功',type:'success'}).show();
									dlg.remove();
									tbl.reload();
								}
							});
						},
						'取消':function(){
							this.remove();
						}
					}
				});
				dlg.show();
			}
			
			$('#btn_testgroup_copy').click(function(){
				
				var items = tbl.getCheckedRow();
				if(items.length!=1){new S.Info({text:'请选择测试组',type:'warn'}).show();return;}
				
				copyTGroup(items[0]);
			});
			
			
		});
	</script>
</head>
<body>
	<div class="filled-box">
		<div class="toolbar">
			<span>　项目：<input class="long" type="text" id="projects_select"></span> 
			<span class="btn" id="btn_testgroup_add"><i class="icons page_add"></i> 增加</span>
			<span class="btn" id="btn_testgroup_edit"><i class="icons page_edit"></i> 编辑</span>
			<span class="btn" id="btn_testgroup_delete"><i class="icons page_delete"></i> 删除</span>
			<span class="btn" id="btn_testgroup_export"><i class="icons saved_exports"></i> 导出报表</span>
			<span class="btn" id="btn_testgroup_copy"><i class="icons page_white_copy"></i> 复制测试组</span>
		</div>
		<div class="content">
			<form>
				<input type="hidden" name="projectId" id="tg_projectId">
			</form>
			<table id="tbl_001" ds="${webcontext }/${pathvar.admin}/blank" height="600">
				<tr>
					<td width="30" seq></td>
					<td width="50" checkall></td>
					<td>测试组</td>
					<td >版本号</td>
					<td >创建时间</td>
					<td >创建者</td>
					<td>开始时间</td>
					<td >结束时间</td>
				</tr>
				<tr>
					<td>@{seq}</td>
					<td><input type="checkbox" name="id" value="@{id}" /></td>
					<td><a href="${webcontext }/${pathvar.admin}/br/testing/tp?tg=@{id}">@{name}</a></td>
					<td>@{version}</td>
					<td>@{createTime}</td>
					<td>@{creatorName}</td>
					<td>@{startTime}</td>
					<td>@{endTime}</td>
				</tr>
			</table>
		</div>
	</div>
</body>
</html>